package com.jdaw.datastructure.tree;

public class ArrBinaryTreeDemo {
    public static void main(String[] args) {
        int[] arr={1,2,3,4,5,6,7};
        ArrBinaryTree arrBinaryTree=new ArrBinaryTree(arr);
        arrBinaryTree.preOrder(0);
    }
}

class ArrBinaryTree{
    public int[] arr;

    public ArrBinaryTree(int[] arr){
        this.arr=arr;
    }

    public void preOrder(int index){
        //index是数组的下标
        if(arr.length==0||arr==null){
            System.out.println("数组为空");
            return;
        }
        System.out.println(arr[index]);
        //向左递归
        if((2*index+1)<arr.length){
            preOrder(2*index+1);
        }
        //向右递归
        if((2*index+2)<arr.length){
            preOrder(2*index+2);
        }
    }
}